import 'package:flutter/material.dart';

/// 分类操作区域组件
class CategoryActionsWidget extends StatelessWidget {
  final VoidCallback? onAdd;
  final VoidCallback? onEdit;
  final VoidCallback? onDelete;
  final VoidCallback? onRefresh;
  final bool hasSelectedCategory; // 是否有选中的分类

  const CategoryActionsWidget({
    super.key,
    this.onAdd,
    this.onEdit,
    this.onDelete,
    this.onRefresh,
    this.hasSelectedCategory = false,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
      decoration: BoxDecoration(
        color: const Color(0xFFEEEEEE),
        borderRadius: BorderRadius.circular(12),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          // 新增分类
          _buildIconButton(
            icon: Icons.create_new_folder_outlined,
            tooltip: '新增分类',
            onPressed: onAdd,
            enabled: true,
          ),
          // 编辑分类
          _buildIconButton(
            icon: Icons.edit_outlined,
            tooltip: '编辑分类',
            onPressed: onEdit,
            enabled: hasSelectedCategory,
          ),
          // 刷新分类
          _buildIconButton(
            icon: Icons.refresh,
            tooltip: '刷新分类',
            onPressed: onRefresh,
            enabled: true,
          ),
          // 删除分类
          _buildIconButton(
            icon: Icons.delete_outline,
            tooltip: '删除分类',
            onPressed: onDelete,
            enabled: hasSelectedCategory,
          ),
        ],
      ),
    );
  }

  Widget _buildIconButton({
    required IconData icon,
    required String tooltip,
    VoidCallback? onPressed,
    bool enabled = true,
  }) {
    return Tooltip(
      message: tooltip,
      child: IconButton(
        icon: Icon(
          icon,
          size: 18,
          color: enabled ? Colors.grey[700] : Colors.grey[400],
        ),
        onPressed: enabled ? onPressed : null,
        splashRadius: 20,
        constraints: const BoxConstraints(
          minWidth: 36,
          minHeight: 36,
        ),
        padding: EdgeInsets.zero,
      ),
    );
  }
}
